package com.swf.seed.os.command.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;

import com.swf.seed.base.SdLetter;
import com.swf.seed.os.annotation.Command;

@Command("date")
public class DateCommand extends CommandAdaptor {

	@Override
	public void option() {
		options.addOption(SdLetter.h, "help", false, "show ip");
		options.addOption(SdLetter.s, "show", false, "show date pattern yyyyMMddHHmmss");
		options.addOption(SdLetter.p, "pattern", true, "set date pattern,default yyyyMMddHHmmss");

	}

	@Override
	void customizedExecute(CommandLine commandLine) throws ParseException {
		if (commandLine.hasOption(SdLetter.s)) {
			System.out.println(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
		}else if (commandLine.hasOption(SdLetter.p)){
			System.out.println(new SimpleDateFormat(commandLine.getOptionValue(SdLetter.p, "yyyyMMddHHmmss")).format(new Date()));
		}

	}

}
